package org.wannatrak.android.formatter;

import android.content.Context;
import org.wannatrak.android.intf.Formatter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Maksim Tulupov maxtulupov@gmail.com
 * @Date: $Date: 2011-06-14 13:32:03 +0000 (Tue, 14 Jun 2011) $ 5:46 PM
 * @version: $Revision: 2 $
 * @id: $Id: Formatters.java 2 2011-06-14 13:32:03Z maxtulupov@gmail.com $
 */
public class Formatters {

     private Map<String, Formatter> formatters = new HashMap<String, Formatter>();

    public Formatters(Context context) {
        formatters.put(TimeFormatter.class.getSimpleName(), new TimeFormatter(context));
        formatters.put(DateTimeFormatter.class.getSimpleName(), new DateTimeFormatter(context));
        formatters.put(Date.class.getSimpleName(), new DateFormatter(context));
    }

    public Formatter getFormatter(String key) {
        Formatter formatter = formatters.get(key);
        if (formatter == null) {
            throw new IllegalArgumentException("no formatter for key " + key);
        }
        return formatter;
    }

    public Formatter getFormatter(Class clazz) {
        return getFormatter(clazz.getSimpleName());
    }
}
